﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using PMSGSC.BLL;
using PMSGSC.DAL;

namespace PMSGSC.App
{
    public partial class frmGridComponent : DevExpress.XtraEditors.XtraForm
    {
        public frmGridComponent()
        {
            InitializeComponent();
            equipmentBindingSource.DataSource = Equipment_BLL.GetAll(frmMain.ship.Ship_ID);
        }
        public Equipment equip;
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            equip = equipmentBindingSource.Current as Equipment;
            this.Close();
        }

        private void gridView1_ShowingEditor(object sender, CancelEventArgs e)
        {
            e.Cancel = true;
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            GridView view = (GridView)sender;
            Point pt = view.GridControl.PointToClient(Control.MousePosition);
            DoRowDoubleClick(view, pt);
        }

        private void DoRowDoubleClick(GridView view, Point pt)
        {
            GridHitInfo info = view.CalcHitInfo(pt);

            if (info.InRow || info.InRowCell)
            {
                if (info.RowHandle != GridControl.NewItemRowHandle)
                {
                    equip = equipmentBindingSource.Current as Equipment;
                    this.Close();
                }
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString();
            }
        }
    }
}